fix(score): raise ValueError when create_score receives None name or value#1733
Open
RudraDudhat2509 wants to merge 1 commit into
Open
Conversation
999a531 to
416f699
Compare
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What does this PR do?
Fixes langfuse/langfuse#14615
create_score() catches a pydantic ValidationError inside the broad except Exception block when name or value is None. The error gets logged at ERROR level but the function still returns None, so the caller has no way to tell the score wasn't created.
This catches ValidationError separately and re-raises it as ValueError so the failure is visible at the call site.
Type of change
Verification
List the main commands you ran:
Full unit suite passes aside from 3 pre-existing failures unrelated to this change (Windows path separator issue in test_serializer.py::test_path, flaky atexit tests under parallel execution in test_prompt_atexit.py). Confirmed these fail identically on main before this change too.
Checklist
code_review.md..env.templateif needed.Greptile Summary
This PR fixes a silent failure in
create_score()where passingNonefornameorvaluecaused a pydanticValidationErrorto be caught by the broadexcept Exceptionblock, logged, and then swallowed — leaving the caller with no indication the score was never created. The fix interceptsValidationErrorbefore the catch-all and re-raises it asValueError.except ValidationErrorclause is added ahead ofexcept Exceptionincreate_score, converting the pydantic error into a caller-visibleValueError.Nonename andNonevalue each raiseValueErrorwith the expected message.Confidence Score: 4/5
Safe to merge; the core fix is correct and well-tested, with one minor behavioral gap when tracing is disabled.
The fix correctly intercepts pydantic ValidationError before the broad except Exception swallows it, and the import is properly placed at module scope. The one gap is that the early-return guard on _tracing_enabled means invalid inputs are not validated at all when tracing is off, so the same None call would raise in a production environment but silently succeed in a tracing-disabled test or staging environment.
The early-return at lines 1917–1918 of langfuse/_client/client.py is worth a second look — consider whether argument validation should be hoisted above it.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[create_score called] --> B{_tracing_enabled?} B -- No --> C[return None\nno validation] B -- Yes --> D[ScoreBody pydantic constructor] D -- ValidationError\ne.g. name=None --> E[NEW: except ValidationError] E --> F[raise ValueError\nInvalid score parameters] D -- success --> G[build event dict] G --> H[add_score_task] H -- Exception --> I[log error, swallow] H -- success --> J[score enqueued]%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[create_score called] --> B{_tracing_enabled?} B -- No --> C[return None\nno validation] B -- Yes --> D[ScoreBody pydantic constructor] D -- ValidationError\ne.g. name=None --> E[NEW: except ValidationError] E --> F[raise ValueError\nInvalid score parameters] D -- success --> G[build event dict] G --> H[add_score_task] H -- Exception --> I[log error, swallow] H -- success --> J[score enqueued]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(score): raise ValueError when create..." | Re-trigger Greptile